<template>
  <div class='search'>
    <f-drawer ref='returnDrawer' :title='title' width='70%' @submit='handleSubmit' @visibleChange='visibleChange'>
      <return-form ref='form1' v-if="drawerVisible&&current=='form1'"></return-form>
    </f-drawer>
  </div>
</template>
<script>
import ReturnForm from "./return_form"

export default {
  name: "ReturnDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      current: "form1",
      formData: {},
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data) {
      this.isEdit = false
      if (data.selectIds) {
        this.isEdit = true
        this.formData = data
      } else {
        this.formData = {}
      }
      this.refs["returnDrawer"].show()
      this.tabClick("form1")
    },
    handleSubmit(callback) {
      this.refs[this.current].handleSubmit(callback => {
        if (callback) {
          this.$emit("success")
        }
        this.refs["returnDrawer"].close()
      })
    },
    visibleChange(drawerVisible) {
      this.drawerVisible = drawerVisible
    },
    tabClick(name) {
      this.current = name
      if (this.current === "form1") {
        this.title = this.isEdit ? "编辑回款" : "添加回款"
      }
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { ReturnForm }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
